1 /* 2 * Copyright (C) 2009 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 module android.ndk.log; 18 19 import core.stdc.stdarg; 20 21 import arsd.jni; 22 import android.ndk; 23 24 extern (C): 25 nothrow: 26 @nogc: 27 28 /** 29 * @addtogroup Logging 30 * @{ 31 */ 32 33 /** 34 * \file 35 * 36 * Support routines to send messages to the Android log buffer, 37 * which can later be accessed through the `logcat` utility. 38 * 39 * Each log message must have 40 * - a priority 41 * - a log tag 42 * - some text 43 * 44 * The tag normally corresponds to the component that emits the log message, 45 * and should be reasonably small. 46 * 47 * Log message text may be truncated to less than an implementation-specific 48 * limit (1023 bytes). 49 * 50 * Note that a newline character ("\n") will be appended automatically to your 51 * log message, if not already there. It is not possible to send several 52 * messages and have them appear on a single line in logcat. 53 * 54 * Please use logging in moderation: 55 * 56 * - Sending log messages eats CPU and slow down your application and the 57 * system. 58 * 59 * - The circular log buffer is pretty small, so sending many messages 60 * will hide other important log messages. 61 * 62 * - In release builds, only send log messages to account for exceptional 63 * conditions. 64 */ 65 66 /** 67 * Android log priority values, in increasing order of priority. 68 */ 69 enum android_LogPriority 70 { 71 /** For internal use only. */ 72 ANDROID_LOG_UNKNOWN = 0, 73 /** The default priority, for internal use only. */ 74 ANDROID_LOG_DEFAULT = 1, /* only for SetMinPriority() */ 75 /** Verbose logging. Should typically be disabled for a release apk. */ 76 ANDROID_LOG_VERBOSE = 2, 77 /** Debug logging. Should typically be disabled for a release apk. */ 78 ANDROID_LOG_DEBUG = 3, 79 /** Informational logging. Should typically be disabled for a release apk. */ 80 ANDROID_LOG_INFO = 4, 81 /** Warning logging. For use with recoverable failures. */ 82 ANDROID_LOG_WARN = 5, 83 /** Error logging. For use with unrecoverable failures. */ 84 ANDROID_LOG_ERROR = 6, 85 /** Fatal logging. For use when aborting. */ 86 ANDROID_LOG_FATAL = 7, 87 /** For internal use only. */ 88 ANDROID_LOG_SILENT = 8 /* only for SetMinPriority(); must be last */ 89 } 90 91 /** 92 * Writes the constant string `text` to the log, with priority `prio` and tag 93 * `tag`. 94 */ 95 int __android_log_write (int prio, const(char)* tag, const(char)* text); 96 97 /** 98 * Writes a formatted string to the log, with priority `prio` and tag `tag`. 99 * The details of formatting are the same as for 100 * [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html). 101 */ 102 int __android_log_print (int prio, const(char)* tag, const(char)* fmt, ...); 103 104 /** 105 * Equivalent to `__android_log_print`, but taking a `va_list`. 106 * (If `__android_log_print` is like `printf`, this is like `vprintf`.) 107 */ 108 int __android_log_vprint ( 109 int prio, 110 const(char)* tag, 111 const(char)* fmt, 112 va_list ap); 113 114 /** 115 * Writes an assertion failure to the log (as `ANDROID_LOG_FATAL`) and to 116 * stderr, before calling 117 * [abort(3)](http://man7.org/linux/man-pages/man3/abort.3.html). 118 * 119 * If `fmt` is non-null, `cond` is unused. If `fmt` is null, the string 120 * `Assertion failed: %s` is used with `cond` as the string argument. 121 * If both `fmt` and `cond` are null, a default string is provided. 122 * 123 * Most callers should use 124 * [assert(3)](http://man7.org/linux/man-pages/man3/assert.3.html) from 125 * `<assert.h>` instead, or the `__assert` and `__assert2` functions provided by 126 * bionic if more control is needed. They support automatically including the 127 * source filename and line number more conveniently than this function. 128 */ 129 void __android_log_assert ( 130 const(char)* cond, 131 const(char)* tag, 132 const(char)* fmt, 133 ...); 134 135 /** 136 * Identifies a specific log buffer for __android_log_buf_write() 137 * and __android_log_buf_print(). 138 */ 139 enum log_id 140 { 141 LOG_ID_MIN = 0, 142 143 /** The main log buffer. This is the only log buffer available to apps. */ 144 LOG_ID_MAIN = 0, 145 /** The radio log buffer. */ 146 LOG_ID_RADIO = 1, 147 /** The event log buffer. */ 148 LOG_ID_EVENTS = 2, 149 /** The system log buffer. */ 150 LOG_ID_SYSTEM = 3, 151 /** The crash log buffer. */ 152 LOG_ID_CRASH = 4, 153 /** The statistics log buffer. */ 154 LOG_ID_STATS = 5, 155 /** The security log buffer. */ 156 LOG_ID_SECURITY = 6, 157 /** The kernel log buffer. */ 158 LOG_ID_KERNEL = 7, 159 160 LOG_ID_MAX = 8 161 } 162 163 alias log_id_t = log_id; 164 165 /** 166 * Writes the constant string `text` to the log buffer `id`, 167 * with priority `prio` and tag `tag`. 168 * 169 * Apps should use __android_log_write() instead. 170 */ 171 int __android_log_buf_write ( 172 int bufID, 173 int prio, 174 const(char)* tag, 175 const(char)* text); 176 177 /** 178 * Writes a formatted string to log buffer `id`, 179 * with priority `prio` and tag `tag`. 180 * The details of formatting are the same as for 181 * [printf(3)](http://man7.org/linux/man-pages/man3/printf.3.html). 182 * 183 * Apps should use __android_log_print() instead. 184 */ 185 int __android_log_buf_print ( 186 int bufID, 187 int prio, 188 const(char)* tag, 189 const(char)* fmt, 190 ...); 191 192 /** @} */